// SignalAnalyzerDlg.h : header file
//
//{{AFX_INCLUDES()
//}}AFX_INCLUDES
#include "teechart\tchart.h"
#include "SHAPIThread.h"

#if !defined(AFX_SIGNALANALYZERDLG_H__F0ED4B69_776F_4D1C_9520_81B1516829A8__INCLUDED_)
#define AFX_SIGNALANALYZERDLG_H__F0ED4B69_776F_4D1C_9520_81B1516829A8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WM_INIT_API_RESULT WM_USER+2
#define WM_CONFIG_API_RESULT WM_USER+4
#define WM_SWEEPCOUNT_API_RESULT WM_USER+6
#define WM_SWEEP_API_RESULT WM_USER+8
/////////////////////////////////////////////////////////////////////////////
// CSignalAnalyzerDlg dialog

class CSignalAnalyzerDlg : public CDialog
{
	DECLARE_EASYSIZE
// Construction
public:
	CSignalAnalyzerDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(CSignalAnalyzerDlg)
	enum { IDD = IDD_SIGNALANALYZER_DIALOG };
	CTChart	m_tchart;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSignalAnalyzerDlg)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	CDialog m_initAPI_dlg;
	CSHAPIThread *m_SHAPIThread;
	HICON m_hIcon;
	LRESULT OnInitAPIResult(WPARAM wParam,LPARAM lParam);
	void OnConfigAPIResult(WPARAM wParam,LPARAM lParam);
	void OnSweepCountAPIResult(WPARAM wParam,LPARAM lParam);
	void OnSweepAPIResult(WPARAM wParam,LPARAM lParam);
	void OnButtonInput(UINT uId);
	// Generated message map functions
	//{{AFX_MSG(CSignalAnalyzerDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnButtonRun();
	afx_msg void OnButtonQuit();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
	afx_msg void OnButtonReset();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnDestroy();
	afx_msg void OnButtonRbw();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	void SetLineChartMaxMinValue();
	void ReadFreqData(double& startFreq, double& stopFreq);
	double m_startFreq;
	double m_stopFreq;
	int m_sweepsize;
	int m_fftsz;
	double *m_xPlotData;
	BOOL m_initFlag;
	BOOL m_stopSweepDataFlag;
	CString m_amplitudeUnitName;
	void StopTimer();
	void StartTimer();
	void DrawLine(double *pX, double *pY, long nNum);
	void DrawMarks(double *pX, double *pY, long nNum);
	static int m_fftszList[];
};

static void TestAPI();
static COleSafeArray ToOleSafeArray(double* pData, long nNum);
static long SearchValueIndex(double* pArray, long len, double data);
static CString formatFreqValue(double freqValue);

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SIGNALANALYZERDLG_H__F0ED4B69_776F_4D1C_9520_81B1516829A8__INCLUDED_)
